var chatApp = angular.module('chatApp', ['ngRoute']);

chatApp.config(['$routeProvider',
	function($routeProvider) {
		$routeProvider.
		when('/', {
			controller: 'mainController'
		}).
		when('/ShowChat/:userId', {
			templateUrl:'template/chat.html',
			controller: 'chatController'
		});
	}
]);
chatApp.controller('mainController', function($scope, $http, $interval) {
	
	$http({method: 'GET', url: '/User'}).
    success(function(data, status, headers, config) {
      $scope.users = data
    });
    $interval(function(){
    	$http({method: 'GET', url: '/User'}).
    success(function(data, status, headers, config) {
      $scope.users = data
    });
}, 20000);
});

chatApp.controller('chatController', function($scope, $routeParams) {
	// create a message to display in our view
	console.log($routeParams)
	$scope.user = $routeParams.userId
});